package com.deyuanyun.pic.ctrl.controller.dto;

import java.math.BigDecimal;

import com.deyuanyun.pic.common.spring.SpringAppliction;
import com.deyuanyun.pic.common.util.StringUtils;
import com.deyuanyun.pic.ctrl.domain.CpRecRecode;
import com.deyuanyun.pic.ctrl.domain.EqptCptestStation;
import com.deyuanyun.pic.ctrl.enumeration.EqptTypeEnum;
import com.deyuanyun.pic.ctrl.service.EQPTBaseService;
import com.deyuanyun.pic.settings.controller.dto.ValveRoomDTO;
import com.deyuanyun.pic.settings.domain.pipe.PipeLine;
import com.deyuanyun.pic.settings.service.pipe.PipeLineService;
import com.deyuanyun.pic.settings.service.pipe.ValveRoomService;
import com.deyuanyun.pic.settings.support.biz.CodeUtil;

/**
 * 阴保整改记录表前台需要的数据DTO。
 * 
 * @author ChenKui
 * @date 2016-06-20
 *
 */
public class CathRepairRecodeDTO extends CpRecRecode{
    
    
    private BigDecimal mileage2;
    private String pipeLineName;//管道名称
    private String pipeValveroomName;//场站阀室名称
    private String eqptType_label;//设备类型
    
    private String nagmName;//附近测试桩名称
    
    //Code表
    private String repairSuggestion_label;//修复建议

    
    public String getPipeLineName() {
        if(pipeLineName == null){
            PipeLineService pipeLineService = SpringAppliction.getBean(PipeLineService.class);
            String pipeLineId = getPipeLineId();
            if(StringUtils.isNotEmpty(pipeLineId)){
                PipeLine pipeLine = pipeLineService.selectByPrimaryKeyCache(pipeLineId);
                pipeLineName = pipeLine.getName();    
            }
        }
        return pipeLineName;
    }

    public String getPipeValveroomName() {
        if(pipeValveroomName == null){
            ValveRoomService valveRoomService = SpringAppliction.getBean(ValveRoomService.class);
            String pipeValveroomId = getPipeValveroomId();
            if(StringUtils.isNotEmpty(pipeValveroomId)){
                ValveRoomDTO valveRoom = valveRoomService.selectByPrimaryKeyCache(getPipeValveroomId());
                pipeValveroomName = valveRoom.getName();    
            }
        }
        return pipeValveroomName;
    }

    public String getEqptType_label() {
        if(eqptType_label == null){
            eqptType_label = EqptTypeEnum.valueOf(getEqptType()).getLabel();
        }
        return eqptType_label;
    }

    public String getRepairSuggestion_label() {
        if(repairSuggestion_label == null){
            repairSuggestion_label = CodeUtil.getName(getRepairSuggestion());
        }
        return repairSuggestion_label;
    }

    public String getNagmName() {
        if(nagmName == null){
            String nagm = getNagm();
            if(StringUtils.isNotEmpty(nagm)){
                EQPTBaseService eQPTBaseService = SpringAppliction.getBean(EQPTBaseService.class);
                EqptCptestStation testStation = eQPTBaseService.queryObjectByPrimaryKey(EqptCptestStation.class, nagm);
                nagmName = testStation.getCustomNumber();
            }
        }
        
        return nagmName;
    }

    public BigDecimal getMileage2() {
        if(mileage2 == null){
            Long mileage = getMileage();
            if(mileage != null){
                mileage2 = new BigDecimal(mileage).movePointLeft(3);   
            }
            
        }
        return mileage2;
    }
    
    

}
